﻿using Hotel_Project.Bean;
using Hotel_Project.BIZ;
using Hotel_Project.Tools.MySqlData_Helps;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace Hotel_Project.HotelForm
{
    public partial class SystemSettingsFrom : Form
    {
        public SystemSettingsFrom()
        {
            InitializeComponent();
            
        }
        private void btSelect_Click(object sender, EventArgs e)
        {
            GuestInfoBIZ guestInfoBIZ= new GuestInfoBIZ();
            List<GuestInfo> guests= guestInfoBIZ.Search(txtName.Text);
            cmbSex.SelectedValue= guests[0].Sex;
            txtIDCard.Text= guests[0].IDCard;
            txtAddress.Text= guests[0].Address;
            txtPhone.Text = guests[0].Phone.ToString();
            txtRemark.Text= guests[0].Remark;
        }

        private void btAdd_Click(object sender, EventArgs e)
        {
            //创建选项卡对象
            TabPage tab1 = new TabPage();

            if (txtName.Text!="")
            {
                tab1.Text = txtName.Text;
                tab1.Name = "首页";
                tab1.BackColor = Color.White;
                tabControl2.Controls.Add(tab1);
            }
            
           
           
        }
        private void tabControl2_Click(object sender, EventArgs e)
        {
            if (null != this.tabControl2.SelectedTab)
            {
                tabControl2.SelectedTab.Controls.Add(IdName);
                tabControl2.SelectedTab.Controls.Add(btSelect);
                tabControl2.SelectedTab.Controls.Add(label12);
                tabControl2.SelectedTab.Controls.Add(cmbSex);
                tabControl2.SelectedTab.Controls.Add(label2);
                tabControl2.SelectedTab.Controls.Add(txtName);
                tabControl2.SelectedTab.Controls.Add(label11);
                tabControl2.SelectedTab.Controls.Add(cmbIDType);
                tabControl2.SelectedTab.Controls.Add(label13);
                tabControl2.SelectedTab.Controls.Add(txtIDCard);
                tabControl2.SelectedTab.Controls.Add(label14);
                tabControl2.SelectedTab.Controls.Add(txtAddress);
                tabControl2.SelectedTab.Controls.Add(label16);
                tabControl2.SelectedTab.Controls.Add(txtPhone);
                tabControl2.SelectedTab.Controls.Add(label18);
                tabControl2.SelectedTab.Controls.Add(txtRemark);
                
            }
        }

        private void SystemSettingsFrom_Load(object sender, EventArgs e)
        {

        }

        private void btSave_Click(object sender, EventArgs e)
        {
            GuestInfoBIZ guestInfoBIZ = new GuestInfoBIZ();
            GuestInfo guestInfo = new GuestInfo();
            guestInfo.Name = txtName.Text;
            guestInfo.Sex = cmbSex.Text;
            guestInfo.Address = txtAddress.Text;
            guestInfo.Remark = txtRemark.Text;
            guestInfo.IDCard = txtIDCard.Text;
            guestInfo.Phone = txtPhone.Text;
            guestInfo.IDCard = txtIDCard.Text;
            guestInfo.Room_number = 1;//int.Parse(label2.Text);
            guestInfo.Date_Time = DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss");
            int rowCount = guestInfoBIZ.Save(guestInfo);
            if (rowCount == 1)
            {
                MessageBox.Show("保存成功！");
            }
            else MessageBox.Show("保存数据失败！！");
        }
    }
}
